package com.cmcc.aregister.ui.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.cmcc.aregister.R;
import com.cmcc.aregister.cs.constant.Arguments;
import com.cmcc.aregister.cs.constant.ConfigUtilHelper;
import com.cmcc.aregister.cs.constant.GlobalSetting;
import com.cmcc.aregister.cs.http.HttpAsyncTask;
import com.cmcc.aregister.cs.model.Department;
import com.cmcc.aregister.cs.model.Doctor;
import com.cmcc.aregister.cs.model.Hospital;
import com.cmcc.aregister.cs.util.PotoalParcelable;
import com.cmcc.aregister.cs.util.Utils;
import com.cmcc.aregister.ui.adapter.DepartmentAdapter;
import com.cmcc.aregister.ui.adapter.DoctorAdapter;
import com.cmcc.aregister.ui.adapter.HospitalAdapter;

/**
 * 我的收藏
 * @author Administrator
 * 
 */
public class CustomManagerActivity extends ParentActivity
{
    private static final String TAG = "CustomManagerActivity";
    // ------view------
    private TextView top_left;
    private TextView top_center;
    private TextView top_right;
    private ListView listView;
    private LinearLayout no_data_layout;
    private TextView no_data_txt;

    // ------parameter------
    private List<Hospital> hospitalList = new ArrayList<Hospital>();
    private List<Doctor> doctorList = new ArrayList<Doctor>();
    private List<Department> departmentList = new ArrayList<Department>();
    private int currentTitleSelect = -1;
    private int currPage;
    private int allPage;
    private int clickPosition;

    // ------view------
    private HospitalAdapter hospitalAdapter;
    private DepartmentAdapter departmentAdapter;
    private DoctorAdapter doctorAdapter;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        init(R.layout.p_custom_manager);
    }

    @Override
    protected void setupData()
    {
        sendGetHospitalListTask("2", ConfigUtilHelper.getMobile(app), "1", "1",
            HttpAsyncTask.CACHE_TYPE_ACTION);
    }

    @Override
    protected void setupView()
    {
        ((ImageView) findViewById(R.id.title))
            .setBackgroundResource(R.drawable.my_collection);
        top_left = (TextView) findViewById(R.id.left_btn);
        top_center = (TextView) findViewById(R.id.center_btn);
        top_right = (TextView) findViewById(R.id.right_btn);
        listView = (ListView) findViewById(R.id.listview);
        no_data_layout = (LinearLayout) findViewById(R.id.no_data_layout);
        no_data_txt = (TextView) findViewById(R.id.no_data_txt);
        top_left.setOnClickListener(onClickListener);
        top_center.setOnClickListener(onClickListener);
        top_right.setOnClickListener(onClickListener);
        listView.setOnItemClickListener(onItemClickListener);
        check(R.id.left_btn, false);
    }

    OnItemClickListener onItemClickListener = new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position,
            long arg3)
        {
            Intent intent = null;
            Map<String, Object> httpMap = new HashMap<String, Object>();
            PotoalParcelable potoal = new PotoalParcelable(httpMap);
            switch (currentTitleSelect)
            {
            case R.id.left_btn:
                intent = new Intent(CustomManagerActivity.this,
                    HospitalDetailActivity.class);
                httpMap.put(Arguments.ACTIVITY_JUMP_HOSPITAL,
                    hospitalList.get(position));
                httpMap.put(Arguments.ACTIVITY_JUMP_AREA_TYPE,
                    hospitalList.get(position).area_type);
                break;
            case R.id.center_btn:
                intent = new Intent(CustomManagerActivity.this,
                    DepartmentDetailActivity.class);
                httpMap.put(Arguments.ACTIVITY_JUMP_DEPARTMENT,
                    departmentList.get(position));
                httpMap.put(Arguments.ACTIVITY_JUMP_AREA_TYPE,
                    departmentList.get(position).area_type);
                if (ConfigUtilHelper.debug)
                {
                    Log.i(TAG, "dep:" + departmentList.get(position));
                }
                break;
            case R.id.right_btn:
                intent = new Intent(CustomManagerActivity.this,
                    DoctorDetailActivity.class);
                httpMap.put(Arguments.ACTIVITY_JUMP_DOCTOR,
                    doctorList.get(position));
                httpMap.put(Arguments.ACTIVITY_JUMP_AREA_TYPE,
                    doctorList.get(position).area_type);
                if (ConfigUtilHelper.debug)
                {
                    Log.i(TAG, "doctor:" + doctorList.get(position));
                }
                break;
            }
            httpMap.put(Arguments.ACTIVITY_JUMP_POSITION, position);
            intent.putExtra(Arguments.INTENT_TO_NEXT_PAGE, potoal);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
    };

    OnClickListener onClickListener = new OnClickListener() {
        @Override
        public void onClick(View v)
        {
            check(v.getId(), true);
        }
    };

    /**
     * 
     * @param id
     * @param hasAnimation 是否需要动画
     */
    public void check(int id, boolean hasAnimation)
    {
        if (currentTitleSelect == id)
        {
            return;
        }
        if (currentTitleSelect > 0)
        {
            findViewById(currentTitleSelect).setSelected(false);
        }
        currentTitleSelect = id;
        findViewById(currentTitleSelect).setSelected(true);
        if (hasAnimation)
        {
            start3DAnimation(listView);
        }
        else
        {

        }
        listView.setVisibility(View.VISIBLE);
        no_data_layout.setVisibility(View.GONE);
    }

    @Override
    public void animFrushView()
    {
        switch (currentTitleSelect)
        {
        case R.id.left_btn:
            top_left
                .setBackgroundResource(R.drawable.collection_hospital_press);
            top_center.setBackgroundResource(R.drawable.collection_dept);
            top_right.setBackgroundResource(R.drawable.collection_doctor);
            if (hospitalAdapter != null)
            {
                if (hospitalList.size() > 0)
                {
                    listView.setAdapter(hospitalAdapter);
                    showNoData(false);
                }
                else
                {
                    showNoData(true);
                }
            }
            else
            {
                listView.setAdapter(null);
                sendGetHospitalListTask("2", ConfigUtilHelper.getMobile(app),
                    "1", "1", HttpAsyncTask.CACHE_TYPE_ACTION);
            }
            break;
        case R.id.center_btn:
            top_left.setBackgroundResource(R.drawable.collection_hospital);
            top_center
                .setBackgroundResource(R.drawable.collection_dept_press);
            top_right.setBackgroundResource(R.drawable.collection_doctor);
            if (departmentAdapter != null)
            {
                if (departmentList.size() > 0)
                {
                    listView.setAdapter(departmentAdapter);
                    showNoData(false);
                }
                else
                {
                    showNoData(true);
                }
            }
            else
            {
                listView.setAdapter(null);
                sendGetDepartmentListTask("2", ConfigUtilHelper.getMobile(app),
                    "", "1", "1", HttpAsyncTask.CACHE_TYPE_ACTION);
            }
            break;
        case R.id.right_btn:
            top_left.setBackgroundResource(R.drawable.collection_hospital);
            top_center.setBackgroundResource(R.drawable.collection_dept);
            top_right.setBackgroundResource(R.drawable.collection_doctor_press);
            if (doctorAdapter != null)
            {
                if (doctorList.size() > 0)
                {
                    listView.setAdapter(doctorAdapter);
                    showNoData(false);
                }
                else
                {
                    showNoData(true);
                }
            }
            else
            {
                listView.setAdapter(null);
                sendGetDoctorListTask("2", ConfigUtilHelper.getMobile(app), "",
                    "", "1", "1", HttpAsyncTask.CACHE_TYPE_ACTION);
            }
            break;
        }
    }

    Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg)
        {
            clickPosition = (Integer) msg.obj;
            switch (msg.what)
            {
            case -1:
                switch (currentTitleSelect)
                {
                case R.id.left_btn:
                    sendGetHospitalListTask("2",
                        ConfigUtilHelper.getMobile(app), "1",
                        currPage + 1 + "", HttpAsyncTask.CACHE_TYPE_ACTION);
                    break;
                case R.id.center_btn:
                    sendGetDepartmentListTask("2",
                        ConfigUtilHelper.getMobile(app), "", "1", currPage + 1
                            + "", HttpAsyncTask.CACHE_TYPE_ACTION);
                    break;
                case R.id.right_btn:
                    sendGetDoctorListTask("2", ConfigUtilHelper.getMobile(app),
                        "", "", "1", currPage + 1 + "",
                        HttpAsyncTask.CACHE_TYPE_ACTION);
                    break;
                }
                break;
            case 0:
                sendCancelAttentionTask(ConfigUtilHelper.getMobile(app),
                    msg.what + "", hospitalList.get(clickPosition).area_type,
                    hospitalList.get(clickPosition).unit_id);
                break;
            case 1:
                sendCancelAttentionTask(ConfigUtilHelper.getMobile(app),
                    msg.what + "", departmentList.get(clickPosition).area_type,
                    departmentList.get(clickPosition).dep_id);
                break;
            case 2:
                sendCancelAttentionTask(ConfigUtilHelper.getMobile(app),
                    msg.what + "", doctorList.get(clickPosition).area_type,
                    doctorList.get(clickPosition).doctor_id);
                break;
            }
        }
    };

    /**
     * 是否显示无数据图片
     * 
     * @param flag
     */
    public void showNoData(boolean flag)
    {
        if (flag)
        {
            listView.setAdapter(null);
            listView.setVisibility(View.GONE);
            no_data_layout.setVisibility(View.VISIBLE);
        }
        else
        {
            listView.setVisibility(View.VISIBLE);
            no_data_layout.setVisibility(View.GONE);
        }
    }

    /**
     * 是否显示无数据图片
     * 
     * @param flag
     */
    public void showNoData(List list)
    {
        if (list.size() == 0)
        {
            listView.setAdapter(null);
            listView.setVisibility(View.GONE);
            no_data_layout.setVisibility(View.VISIBLE);
        }
        else
        {
            listView.setVisibility(View.VISIBLE);
            no_data_layout.setVisibility(View.GONE);
        }
    }

    public void setView()
    {
        switch (currentTitleSelect)
        {
        case R.id.left_btn:
            if (hospitalList.size() > 0)
            {
                if (hospitalAdapter == null)
                {
                    hospitalAdapter = new HospitalAdapter(context,
                        hospitalList, handler, currPage, allPage, true);
                    listView.setAdapter(hospitalAdapter);
                }
                else
                {
                    hospitalAdapter.list = hospitalList;
                    hospitalAdapter.currPage = currPage;
                    hospitalAdapter.allPage = allPage;
                    hospitalAdapter.notifyDataSetChanged();
                }
                showNoData(false);
            }
            else
            {
                no_data_txt.setText(R.string.dlg_no_fav_hos);
                showNoData(true);
            }
            break;
        case R.id.center_btn:
            if (departmentList.size() > 0)
            {
                if (departmentAdapter == null)
                {
                    departmentAdapter = new DepartmentAdapter(context,
                        departmentList, handler, currPage, allPage, true);
                    listView.setAdapter(departmentAdapter);
                }
                else
                {
                    departmentAdapter.list = departmentList;
                    departmentAdapter.currPage = currPage;
                    departmentAdapter.allPage = allPage;
                    departmentAdapter.notifyDataSetChanged();
                }
                showNoData(false);
            }
            else
            {
                no_data_txt.setText(R.string.dlg_no_fav_dep);
                showNoData(true);
            }
            break;
        case R.id.right_btn:
            if (doctorList.size() > 0)
            {
                if (doctorAdapter == null)
                {
                    doctorAdapter = new DoctorAdapter(context, doctorList,
                        handler, currPage, allPage, true);
                    listView.setAdapter(doctorAdapter);
                }
                else
                {
                    doctorAdapter.list = doctorList;
                    doctorAdapter.currPage = currPage;
                    doctorAdapter.allPage = allPage;
                    doctorAdapter.notifyDataSetChanged();
                }
                showNoData(false);
            }
            else
            {
                no_data_txt.setText(R.string.dlg_no_fav_doc);
                showNoData(true);
            }
            break;
        }
    }

    /**
     * 获取医院列表
     */
    private HttpAsyncTask sendGetHospitalListTask;

    /**
     * 
     * @param area_type 区域类别 0：本地 1：异地 2 所有
     * @param mobile 手机号码 如果为空，则不处理关注相关数据
     * @param is_attention 是否已关注 缺省时查询全部，1只返回已关注数据
     * @param page 页数 0 表示不分页为所有，分页从1开始
     * @param pageSize 每页记录数 默认为10
     */
    protected void sendGetHospitalListTask(String area_type, String mobile,
        String is_attention, String page, int cacheType)
    {
        logger.d("----------sendGetHospitalListTask----------");
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("area_type", area_type);
        parameterMap.put("mobile", mobile);
        parameterMap.put("is_attention", is_attention);
        parameterMap.put("page", page);
        parameterMap.put("pageSize", Arguments.pageSize);
        String getHospitalListUrl = Utils.changeUrl(
            Arguments.SERVER_URL_GET_HOSPITAL_LIST, parameterMap);
        if (cacheType == HttpAsyncTask.CACHE_TYPE_ACTION)
        {
            sendGetHospitalListTask = new HttpAsyncTask(HttpAsyncTask.GET,
                GlobalSetting.XML_HOSPITAL_LIST, getHospitalListUrl, cacheType,
                true);
            showProgressDialog();
        }
        else
        {
            sendGetHospitalListTask = new HttpAsyncTask(HttpAsyncTask.GET,
                GlobalSetting.XML_HOSPITAL_LIST, getHospitalListUrl, cacheType,
                false);
        }
        sendGetHospitalListTask.setUIHandler(sendGetHospitalListHandler);
        mHttpManager.execute(sendGetHospitalListTask);
    }

    @SuppressWarnings("unchecked")
    Handler sendGetHospitalListHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            logger.d("----------sendGetHospitalListHandler----------");
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                dismissProgressDialog();
                if (msg.obj != null)
                {
                    try
                    {
                        Map<String, Object> httpMap = (Map<String, Object>) msg.obj;
                        List<Hospital> hospital_1 = (List<Hospital>) httpMap
                            .get(Arguments.XML_HOSPITAL_LIST);
                        allPage = Integer.parseInt((String) httpMap
                            .get(Arguments.XML_ALLPAGE));
                        currPage = Integer.parseInt((String) httpMap
                            .get(Arguments.XML_CURRPAGE));
                        if (currPage == 1)
                        {
                            hospitalList = hospital_1;
                        }
                        else
                        {
                            hospitalList.addAll(hospital_1);
                        }
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                        allPage = currPage;
                    }
                }
                setView();
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
                allPage = currPage;
                setView();
                break;
            }
        }
    };

    /**
     * 获取科室列表
     */
    private HttpAsyncTask sendGetDepartmentListTask;

    /**
     * 
     * @param area_type 区域类别 0：本地 1：异地 2 所有
     * @param mobile 手机号码 如果为空，则不处理关注相关数据
     * @param unit_id 医院id 如果为空，获取所有的科室， 如果不为空，获取所在医院的科室
     * @param is_attention 是否已关注 缺省时查询全部，1只返回已关注数据
     * @param page 页数 0 表示不分页为所有，分页从1开始
     * @param pageSize 每页记录数 默认为10
     */
    protected void sendGetDepartmentListTask(String area_type, String mobile,
        String unit_id, String is_attention, String page, int cache_type)
    {
        logger.d("----------sendGetDepartmentListTask----------" + page);
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("area_type", area_type);
        parameterMap.put("mobile", mobile);
        parameterMap.put("unit_id", unit_id);
        parameterMap.put("is_attention", is_attention);
        parameterMap.put("page", page);
        parameterMap.put("pageSize", Arguments.pageSize);
        String getDepartmentListUrl = Utils.changeUrl(
            Arguments.SERVER_URL_GET_DEPARTMENT_LIST, parameterMap);
        if (ConfigUtilHelper.debug)
        {
            Log.i(TAG, "收藏科室地址：" + getDepartmentListUrl);
        }
        if (cache_type == HttpAsyncTask.CACHE_TYPE_ACTION)
        {
            sendGetDepartmentListTask = new HttpAsyncTask(HttpAsyncTask.GET,
                GlobalSetting.XML_DEPARTMENT_LIST, getDepartmentListUrl,
                cache_type, true);
            showProgressDialog();
        }
        else
        {
            sendGetDepartmentListTask = new HttpAsyncTask(HttpAsyncTask.GET,
                GlobalSetting.XML_DEPARTMENT_LIST, getDepartmentListUrl,
                cache_type, false);
        }
        sendGetDepartmentListTask
            .setUIHandler(sendGetDepartmentListTaskHandler);
        mHttpManager.execute(sendGetDepartmentListTask);
    }

    @SuppressWarnings("unchecked")
    Handler sendGetDepartmentListTaskHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            logger.d("----------sendGetDepartmentListTaskHandler----------");
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                dismissProgressDialog();
                if (msg.obj != null)
                {
                    try
                    {
                        Map<String, Object> httpMap = (Map<String, Object>) msg.obj;
                        allPage = Integer.parseInt((String) httpMap
                            .get(Arguments.XML_ALLPAGE));
                        currPage = Integer.parseInt((String) httpMap
                            .get(Arguments.XML_CURRPAGE));
                        List<Department> departmentList_1 = (List<Department>) httpMap
                            .get(Arguments.XML_DEPARTMENT_LIST);
                        if (currPage == 1)
                        {
                            departmentList = departmentList_1;
                        }
                        else
                        {
                            departmentList.addAll(departmentList_1);
                        }
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                        allPage = currPage;
                    }
                }
                setView();
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
                allPage = currPage;
                setView();
                break;
            }
        }
    };

    /**
     * 获取医生列表
     */
    private HttpAsyncTask sendGetDoctorListTask;

    /**
     * 
     * @param area_type 区域类别 0：本地 1：异地 2 所有
     * @param mobile 手机号码 如果为空，则不处理关注相关数据
     * @param unit_id 医院id 如果为空，获取所有的科室， 如果不为空，获取所在医院的科室
     * @param dep_id 科室id 如果为空，获取所有的医生， 如果不为空，获取所在科室的医生
     * @param is_attention 是否已关注 缺省时查询全部，1只返回已关注数据
     * @param page 页数 0 表示不分页为所有，分页从1开始
     * @param pageSize 每页记录数 默认为10
     */
    protected void sendGetDoctorListTask(String area_type, String mobile,
        String unit_id, String dep_id, String is_attention, String page,
        int cache_type)
    {
        logger.d("----------sendGetDoctorListTask----------");
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("area_type", area_type);
        parameterMap.put("mobile", mobile);
        parameterMap.put("unit_id", unit_id);
        parameterMap.put("dep_id", dep_id);
        parameterMap.put("is_attention", is_attention);
        parameterMap.put("page", page);
        parameterMap.put("pageSize", Arguments.pageSize);
        String getDoctorListUrl = Utils.changeUrl(
            Arguments.SERVER_URL_GET_DOCTOR_LIST, parameterMap);
        if (cache_type == HttpAsyncTask.CACHE_TYPE_ACTION)
        {
            sendGetDoctorListTask = new HttpAsyncTask(HttpAsyncTask.GET,
                GlobalSetting.XML_DOCTOR_LIST, getDoctorListUrl, cache_type,
                true);
            showProgressDialog();
        }
        else
        {
            sendGetDoctorListTask = new HttpAsyncTask(HttpAsyncTask.GET,
                GlobalSetting.XML_DOCTOR_LIST, getDoctorListUrl, cache_type,
                false);
        }
        sendGetDoctorListTask.setUIHandler(sendGetDoctorListTaskHandler);
        mHttpManager.execute(sendGetDoctorListTask);
    }

    @SuppressWarnings("unchecked")
    Handler sendGetDoctorListTaskHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            logger.d("----------sendGetDoctorListTaskHandler----------");
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                dismissProgressDialog();
                if (msg.obj != null)
                {
                    try
                    {
                        Map<String, Object> httpMap = (Map<String, Object>) msg.obj;
                        allPage = Integer.parseInt((String) httpMap
                            .get(Arguments.XML_ALLPAGE));
                        currPage = Integer.parseInt((String) httpMap
                            .get(Arguments.XML_CURRPAGE));
                        List<Doctor> doctorList_1 = (List<Doctor>) httpMap
                            .get(Arguments.XML_DOCTOR_LIST);
                        if (currPage == 1)
                        {
                            doctorList = doctorList_1;
                        }
                        else
                        {
                            doctorList.addAll(doctorList_1);
                        }
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                        allPage = currPage;
                    }
                }
                setView();
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail), getString(R.string.close));
                allPage = currPage;
                setView();
                break;
            }
        }
    };

    /**
     * 取消关注
     */
    private HttpAsyncTask sendCancelAttentionTask;

    /**
     * 
     * @param mobile 手机号码
     * @param attentionType 关注类别 N 0：关注医院1:关注科室2:关注医生
     * @param area_type area_type 区域ID Y 0是本地 1是异地 2是全部
     * @param id 相应id
     */
    private void sendCancelAttentionTask(String mobile, String attentionType,
        String area_type, String id)
    {
        Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("mobile", mobile);
        parameterMap.put("area_type", area_type);
        parameterMap.put("attentionType", attentionType);
        if ("0".equals(attentionType))
        {
            parameterMap.put("unit_id", id);
        }
        else if ("1".equals(attentionType))
        {
            parameterMap.put("dep_id", id);
        }
        else
        {
            parameterMap.put("doctor_id", id);
        }
        String cancelAttentionUrl = Utils.changeUrl(
            Arguments.SERVER_URL_CANCEL_ATTENTION, parameterMap);
        sendCancelAttentionTask = new HttpAsyncTask(HttpAsyncTask.GET,
            GlobalSetting.XML_CANCEL_ATTENTION, cancelAttentionUrl,
            HttpAsyncTask.CACHE_TYPE_ACTION, false);
        showProgressDialog();
        sendCancelAttentionTask.setUIHandler(sendCancelAttentionTaskHandler);
        mHttpManager.execute(sendCancelAttentionTask);
    }

    @SuppressWarnings("unchecked")
    Handler sendCancelAttentionTaskHandler = new Handler() {
        public void handleMessage(Message msg)
        {
            logger.d("----------sendCancelAttentionTaskHandler----------");
            switch (msg.what)
            {
            case HttpAsyncTask.TASK_NOTIFY_RETURN_DATA:
                dismissProgressDialog();
                if (msg.obj != null)
                {
                    try
                    {
                        Map<String, Object> httpMap = (Map<String, Object>) msg.obj;
                        String status = (String) httpMap
                            .get(Arguments.XML_STATUS);
                        String message = (String) httpMap
                            .get(Arguments.XML_MESSAGE);
                        showSingleAlertDlg(getString(R.string.notice), message,
                            getString(R.string.close));
                        if ("0".equals(status))
                        {
                            switch (currentTitleSelect)
                            {
                            case R.id.left_btn:
                                if (hospitalAdapter != null)
                                {
                                    Hospital hospital = hospitalList
                                        .remove(clickPosition);
                                    app.changeAttention(0, hospital.unit_id,
                                        "0");
                                    if (hospitalList.size() > 0)
                                    {
                                        hospitalAdapter.list = hospitalList;
                                        hospitalAdapter.notifyDataSetChanged();
                                        showNoData(false);
                                    }
                                    else
                                    {
                                        no_data_txt
                                            .setText(R.string.dlg_no_fav_hos);
                                        showNoData(true);
                                    }
                                }
                                break;
                            case R.id.center_btn:
                                if (departmentAdapter != null)
                                {
                                    Department department = departmentList
                                        .remove(clickPosition);
                                    app.changeAttention(1, department.dep_id,
                                        "0");
                                    if (departmentList.size() > 0)
                                    {
                                        departmentAdapter.list = departmentList;
                                        departmentAdapter
                                            .notifyDataSetChanged();
                                        showNoData(false);
                                    }
                                    else
                                    {
                                        no_data_txt
                                            .setText(R.string.dlg_no_fav_dep);
                                        showNoData(true);
                                    }
                                }
                                break;
                            case R.id.right_btn:
                                if (doctorAdapter != null)
                                {
                                    Doctor doctor = doctorList
                                        .remove(clickPosition);
                                    app.changeAttention(2, doctor.doctor_id,
                                        "0");
                                    if (doctorList.size() > 0)
                                    {
                                        doctorAdapter.list = doctorList;
                                        doctorAdapter.notifyDataSetChanged();
                                        showNoData(false);
                                    }
                                    else
                                    {
                                        no_data_txt
                                            .setText(R.string.dlg_no_fav_doc);
                                        showNoData(true);
                                    }
                                }
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        e.printStackTrace();
                        showSingleAlertDlg(getString(R.string.notice),
                            getString(R.string.read_fail),
                            getString(R.string.close));
                    }
                }
                else
                {
                    showSingleAlertDlg(getString(R.string.notice),
                        getString(R.string.cancel_fail),
                        getString(R.string.close));
                }
                break;
            case HttpAsyncTask.TASK_NOTIFY_CONNECTION_FAIL:
                dismissProgressDialog();
                showSingleAlertDlg(getString(R.string.notice),
                    getString(R.string.read_fail),
                    getString(R.string.close));
                break;
            }
        }
    };

    @Override
    protected void setTaskHandlerNull()
    {
        if (sendGetHospitalListTask != null)
        {
            sendGetHospitalListTask.setTaskBindingHandler(null);
        }
        if (sendGetDoctorListTask != null)
        {
            sendGetDoctorListTask.setTaskBindingHandler(null);
        }
        if (sendGetDepartmentListTask != null)
        {
            sendGetDepartmentListTask.setTaskBindingHandler(null);
        }
        if (sendCancelAttentionTask != null)
        {
            sendCancelAttentionTask.setTaskBindingHandler(null);
        }
    }

    @Override
    protected void onResume()
    {
        super.onResume();
        if (app.changeAttention)
        {
            switch (app.type)
            {
            case 0:
                if (hospitalAdapter != null)
                {
                    hospitalList.remove(app.position);
                    if (hospitalList.size() > 0)
                    {
                        hospitalAdapter.list = hospitalList;
                        hospitalAdapter.notifyDataSetChanged();
                        showNoData(false);
                    }
                    else
                    {
                        showNoData(true);
                    }
                }
                break;
            case 1:
                if (departmentAdapter != null)
                {
                    departmentList.remove(app.position);
                    if (departmentList.size() > 0)
                    {
                        departmentAdapter.list = departmentList;
                        departmentAdapter.notifyDataSetChanged();
                        showNoData(false);
                    }
                    else
                    {
                        showNoData(true);
                    }
                }
                break;
            case 2:
                if (doctorAdapter != null)
                {
                    doctorList.remove(app.position);
                    if (doctorList.size() > 0)
                    {
                        doctorAdapter.list = doctorList;
                        doctorAdapter.notifyDataSetChanged();
                        showNoData(false);
                    }
                    else
                    {
                        showNoData(true);
                    }
                }
                break;
            }
            app.changeAttention = false;
            app.position = -1;
            app.type = -1;
            app.attentioin = "";
        }
    }
}